<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ats_plan_curriculum</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../../res/js/Tools.js"></script>
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../res/echarts/xm-select.js"></script>
    <link href="../../res/echarts/eleTree.css" rel="stylesheet"/>
    <script src="../../res/echarts/eleTree.js"></script>
    <style>
        .layui-form-item .layui-input-inlinetwo {
            float: left;
            width: 130px;
            margin-right: 10px;
        }

        #cilicili span:hover {
            cursor: pointer;
        }

        .blala span:hover {
            cursor: pointer;
        }

        #bindone span:hover {
            cursor: pointer;
        }

        #bindtwo span:hover {
            cursor: pointer;
        }

        #blala span:hover {
            cursor: pointer;
        }

        #bindthree span:hover {
            cursor: pointer;
        }

        #loveyouni span:hover {
            cursor: pointer;
        }

        .layui-form-item .layui-input-inlinethree {
            float: left;
            width: 182px;
            margin-right: 10px;
        }

        #closeone:hover {
            cursor: pointer;
        }


        .zbs {
            overflow: hidden;
            padding: 10px;
            padding-left: 50px;
            padding-right: 50px;

        }
    </style>
    <script>
        $.ajaxSetup({
            async: false
        });
        $(function () {
            //window.setInterval(planDate,1000);
            var coachId = loginObj.manager.clerkId;
            $("#coachId").val(coachId);
            var creater = loginObj.manager.userName;
            $("#creater").val(creater);
            //window.setInterval(gg,500)
        })

        function planDate(value) {
            //得到下周一的时间
            var dateOne = getNextWeek(1);
            //得到下周日的时间
            var dateTwo = getNextWeek(7);
            //得到文本框输入的时间
            if (value) {
                if (value < dateOne || value > dateTwo) {
                    $("#planDate").val("");
                    layer.msg("请输入制定周以内的日期区间!!");
                }
            }

        }

        function gg() {
            if ($("#planDate").val()) {
                $("#city").val();  // 选中项目的value值
                $("select option:checked").text(); // 选中项目的显示值
                //时间格式转换
                var date = new Date($("#planDate").val());
                var newDate = dateToStr(date);
                //获取当天是星期几
                var ji = "日一二三四五六".charAt(date.getDay());
                //alert(newDate+" 周"+ji);
                $("#curriculumName").val(" 周" + ji + "-" + $("#planDate").val() + "-" + $("select option:checked").text());
            }
        }

    </script>
</head>
<body>

<form class="layui-form" action="" id="formDId" lay-filter="example" method="post" enctype="multipart/form-data">
    <input type="hidden" name="curriculumId" id="curriculumId">
    <input type="hidden" name="creater" id="creater">
    <input type="hidden" name="sportName" id="sportName">
    <input type="hidden" name="sportId" id="sportId">

    <input type="hidden" name="coachId" id="coachId">
    <!-- 判断暂存用的字段  -->
    <input type="hidden" name="zancun" id="zancun">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">定制日期</label>
            <div class="layui-input-inlinethree">
                <input type="text" class="layui-input" readonly="" lay-verify="required" id="planDate" name="planDate"
                       placeholder="请输入制定时间">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">定制时间:</label>
            <div id="checkBox1" class="layui-input-block">
                <select name="city" lay-verify="required" id="city" lay-filter="city">
                    <option value="早晨">早晨</option>
                    <option value="上午">上午</option>
                    <option value="中午">中午</option>
                    <option value="下午">下午</option>
                    <option value="晚上">晚上</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">应到人数</label>
            <div class="layui-input-inlinethree">
                <input type="text" name="weekShould" required lay-verify="required" Maxlength="50" id="weekShould"
                       lay-verify="title" autocomplete="off" placeholder="请输入应到人数" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label" style="font-size: 13px">实到人数</label>
            <div class="layui-input-inlinethree">
                <input type="text" name="weekReality" lay-verify="required" Maxlength="50" id="weekReality"
                       lay-verify="title" autocomplete="off" placeholder="请输入实到人数" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">运动负荷</label>
            <div class="layui-input-inlinethree">
                <input type="text" name="weekLoad" lay-verify="required|number" Maxlength="50" id="weekLoad"
                       lay-verify="title" autocomplete="off" placeholder="%" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">运动强度</label>
            <div class="layui-input-inlinethree">
                <input type="text" name="curIntensity" lay-verify="required|number" Maxlength="50" id="curIntensity"
                       lay-verify="title" autocomplete="off" placeholder="请输入运动强度" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">运动量</label>
            <div class="layui-input-inlinethree">
                <input type="text" name="curScale" lay-verify="required|number" Maxlength="50" id="curScale"
                       lay-verify="title" autocomplete="off" placeholder="请输入运动量" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">计划名称</label>
            <div class="layui-input-inlinethree">
                <input type="text" name="curriculumName" Readonly=“true” style="width: 350px;cursor:not-allowed;"
                       lay-verify="required" Maxlength="50" id="curriculumName" lay-verify="title" autocomplete="off"
                       placeholder="请输入计划名称" class="layui-input">
            </div>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">训练课任务</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入训练课任务" required lay-verify="required" Maxlength="1000" class="layui-textarea"
                      name="weekTask" id="weekTask"></textarea>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn site-demo-active" lay-submit lay-filter="formDemo"
                        id="submitTwo">立即提交
                </button>
            </div>
        </div>
    </div>
</form>
<script>
    var overZhiBiao = "";
    layui.use(['laydate', 'layer'], function () {
        var laydate = layui.laydate;
        var layer = layui.layer;
        //时间范围
        laydate.render({
            elem: '#planDate'
            , type: 'date'
            , btns: ['clear', 'now']
            , done: function (value, date, endDate) {
                planDate(value);
                gg();
            }, change: function (value, date, endDate) {
                planDate(value);
                gg();
            }
        });
    });
    var form = null;
    layui.config({
        base: '../atsBaseItem/module/'
    }).extend({
        treeSelect: 'treeSelect/treeSelect',
    }).use(['form'], function () {
        form = layui.form;
        var it = 0;
        var submitOne = 0;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            var index1 = layer.load(0);
            it = 1;
            save(data, index1);
            return false;
        });
        form.on('select(city)', function (data) {
            gg();
            form.render('select');//select是固定写法 不是选择器
        });

        function save(data, index1) {
            //取到修改
            var curriculumIdone = getQueryString("curriculumIdone");
            //有周的Id就取周Id
            var weekId = getQueryString("weekId");
            if (submitOne == 1) {
                curriculumIdone = null;
            }
            var urlone = "../../planCurriculumMapperController/selectCurriculumName";
            var datatwo = {curriculumName: $("#curriculumName").val()};
            $.post(urlone, datatwo, function (objtwo) {
                if (objtwo > 0) {
                    layer.close(index1);
                    layer.msg("课计划名称以重复，请修改!");
                    return false;
                } else {
                    //实到人数
                    var weekReality = parseInt($("#weekReality").val());
                    //应到人数
                    var weekShould = parseInt($("#weekShould").val());
                    if (weekReality > weekShould) {
                        layer.close(index1);
                        layer.msg("实到人数大于应到人数，请修改以后在提交!");
                        return false;
                    }
                    // 单击之后提交按钮不可选,防止重复提交
                    $("#submitOne").val("正在提交");
                    $("#submitTwo").val("正在提交");
                    var ide = getQueryString("weekId");
                    // 增加属性
                    $('.site-demo-active').attr('disabled', 'disabled');
                    var url = "../../planCurriculumMapperController/curricuAddOrupdate";
                    var isva = 1;
                    var datattt = {
                        creater: $("#creater").val(),
                        curriculumName: $("#curriculumName").val(),
                        weekShould: $("#weekShould").val(),
                        weekReality: $("#weekReality").val(),
                        planDate: $("#planDate").val(),
                        weekLoad: $("#weekLoad").val(),
                        curIntensity: $("#curIntensity").val(),
                        curScale: $("#curScale").val(),
                        weekTask: $("#weekTask").val(),
                        itemName: $("#sportName").val(),
                        sportId: $("#sportId").val(),
                        coachId: $("#coachId").val(),
                        isva: isva,
                        curriculumId: $("#curriculumId").val()
                    };

                    $.ajax({
                        url: url,
                        async: true,
                        type: "post",
                        data: datattt,
                        dataType: "json",
                        success: function (obj) {
                            layer.close(index1);
                            layer.msg("操作成功！", {
                                icon: 1,
                                time: 1000 //1秒关闭(如果不配置默认三秒)
                            }, function () {

                                //询问框
                                if (it === 1) {
                                    layer.confirm('你要制定下一个课计划吗？', {
                                        btn: ['是', '否'] //按钮
                                    }, function () {
                                        submitOne = 1;
                                        $("#submitTwo").val("立即提交");
                                        // 增加属性
                                        $('.site-demo-active').attr('disabled', false);
                                        $("input").each(function (index, item) {
                                            if (index < 13 && index != 2 && index != 3 && index != 4 && index != 1 && index != 7) {
                                                $(this).val("");
                                            }
                                        })
                                        $("input[name='zhiBiao']").each(
                                            function () {
                                                if ($(this).val() == 0) {
                                                    $(this).val("");
                                                }
                                            })
                                        $("#weekTask").val("");
                                        layer.msg('请开始添加新的数据', {icon: 1});

                                    }, function () {
                                        layer.close(index);
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);//关闭当前页*/
                                    });
                                } else {
                                    layer.close(index);
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);//关闭当前页*/
                                }

                            });
                        }

                    });
                }
            }, "json");


        }


        findSportId();
        var ide = getQueryString("curriculumId");
        var curriculumIdone = getQueryString("curriculumIdone");
        console.info(curriculumIdone);
        if (curriculumIdone) {
            $("#curriculumId").val(curriculumIdone);
            var url = "../../planCurriculumMapperController/findByCur";
            var data = {curriculumId: curriculumIdone};
            $.post(url, data, function (obj) {
                $("#curriculumName").val(obj.curriculumName);
                $("#weekShould").val(obj.weekShould);
                $("#weekReality").val(obj.weekReality);
                $("#planDate").val(obj.planDate);
                $("#weekLoad").val(obj.weekLoad);
                $("#curIntensity").val(obj.curIntensity);
                $("#curScale").val(obj.curScale);
                $("#weekTask").val(obj.weekTask);
                var curriculumName = obj.curriculumName;
                var str = curriculumName.split("-");
                $("#city").val(str[4]);
                form.render('select');
            }, "json");
        }
        var data = null;


        function findSportId() {
            //首先查出专业外键，根据专业查专业名字
            var urlFour = "../../planCurriculumMapperController/findCoachexp";
            var dataFour = {coachId: $("#coachId").val()};
            $.post(urlFour, dataFour, function (obj) {
                $("#sportId").val(obj.expertSpecia);
                //查体育专业名字
                var url = "../../planCurriculumMapperController/findCoachexpone";
                var data = {sportId: obj.expertSpecia};
                $.post(url, data, function (objs) {
                    $("#sportName").val(objs.sportName);
                }, "json");
            }, "json");
        }
    });


</script>
</body>
</html>